<template>
	<view class="container">
		<view class="user-section">
			<!-- <image class="bg" src="/static/bj.jpg"></image> -->
			<view class="user-info-box">
				<view class="member-top-c">
					<template>
						<image class='portrait' mode="aspectFill" :src='userDetailInfo.icon'></image>
						<view class='user-name' style="text-align: center;font-size: 30rpx;">
							{{ userDetailInfo.nickname }}</view>
						<view class='user-name' style="text-align: center;font-size: 30rpx;padding-top: 20rpx;">当前门店余额
							：{{integral}}分<text style="font-size: 20rpx;color: aliceblue;">({{integral/100}}元)</text>
						</view>
					</template>
				</view>
			</view>
		</view>
		<view style="background-color: #f6f4ef;height: 1000rpx;">
			<view style="text-align: center;padding-top: 20rpx;">
				<text style="color: #1296db;letter-spacing: 1rpx;font-weight: 800;">请选择充值套餐</text>
			</view>
			<view class="meal-content">
				<view :class="panduan==index ? 'meal-item-selected':'meal-item' " v-for="(item, index) in meals"
					:key="index" @click="changePrice(item,$event,index)">
					<text>{{item.price}}元</text>
				</view>
			</view>
			<view style="height: 300rpx;padding: 20rpx;">
				<text style="color: #838383;">充值提示：</text></br>
				<text style="color: #838383;">充值如果发生任何异常、问题请联系商家</text></br>
				<text style="color: #838383;" @click="call(store.servicePhone)">联系电话:{{store.servicePhone}}</text></br>
				<view style="margin-top: 50rpx;">
					<text style="color: #1296db;font-weight: 600;font-size: 35rpx;">优惠：</text></br>
					<text style="color: #1296db;font-weight: 600;font-size: 35rpx;" v-if="desc!=''">{{desc}}</text>
					<text style="color: #1296db;font-weight: 600;font-size: 35rpx;" v-if="desc==''">请选择充值套餐</text>
				</view>
			</view>
			<view style="height: 100rpx;margin-top: 80rpx;">
				<button @click="generateOrder()" style="width: 700rpx;background-color: #1296db;color: white;">
					<text>充值{{youhui}}</text>
				</button>
			</view>
		</view>
	</view>
</template>
<script>
	import Api from '@/common/api';
	import listCell from '@/components/mix-list-cell';
	import {
		mapState
	} from 'vuex';
	import store from '../../store';
	export default {
		components: {
			listCell
		},
		data() {
			return {
				userDetailInfo: {},
				currentCoachId: null,
				role: '0', //0:学员 1:教练
				meals: [],
				desc: '',
				panduan: 999,
				price: 0,
				rechargeMealId: null,
				storeId: null,
				giveMoney: 0,
				integral: 0,
				youhui: '',
				store: null
			};
		},
		async onShow() {},
		async onLoad(options) {
			console.log("onLoad========" + this.hasLogin);
			if (this.hasLogin) {
				let username = this.userInfo.userInfo.username;
				let params = {
					memberId: this.userInfo.userInfo.id
				};
				let data1 = await Api.apiCall('get', Api.index.userInfo, params);
				console.log(data1);
				this.userDetailInfo = data1.member;
				this.currentCoachId = this.userInfo.userInfo.coachId;
				this.getIntegral(this.userInfo.userInfo.id, options.storeId);
			}
			this.storeId = options.storeId;
			this.getStoreById(options.storeId);
			this.getRechargeMeal(options.storeId);
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			call(mobile) {
				if (typeof(mobile) == 'undefined' || mobile == '') {

				} else {
					uni.makePhoneCall({
						phoneNumber: mobile,
						success: function() {
							console.log('拨打电话成功');
						},
						fail() {
							console.log('打电话失败了');
						}
					})
				}
			},
			async getIntegral(memberId, storeId) {
				let params = {
					memberId: memberId,
					storeId: storeId
				}
				let data = await Api.apiCall('get', Api.qsg.getIntegral, params);
				if (data) {
					this.integral = data.integral
				}
			},
			async getStoreById(storeId) {
				let data = await Api.apiCall('get', Api.store.getStoreById, {
					storeId: storeId
				});
				if (data) {
					this.store = data
				}
			},
			toBuyVip() {
				uni.navigateTo({
					url: '/pages/user/vip/buyvip?pushId=0'
				});
			},
			async changePrice(item, e, index) {
				this.panduan = index;
				this.desc = item.name;
				this.price = item.price;
				this.rechargeMealId = item.id;
				this.giveMoney = item.giveMoney;
				this.youhui = this.price + '送' + this.giveMoney
			},
			async getRechargeMeal(storeId) {
				let params = {
					storeId: storeId
				};
				let data = await Api.apiCall('get', Api.qsg.getRechargeMeal, params);
				if (data) {
					this.meals = data;
				}
			},
			async generateOrder() {
				let that = this;
				if (null == that.rechargeMealId) {
					uni.showToast({
						icon: 'none',
						title: '请选择充值套餐'
					})
					return false;
				}
				let params = {
					rechargeMealId: that.rechargeMealId,
					storeId: that.storeId,
					mealName: that.desc,
					price: that.price,
					giveMoney: that.giveMoney
				};
				let data = await Api.apiCall('post', Api.order.createRechargeOrder, params);
				console.log(data);
				if (data) {
					let id = data.id;
					let price = this.price;
					let url = `/pages/money/rechargepay?id=${id}&price=${price}`;
					uni.redirectTo({
						url: url
					});
				} else {
					that.$core.msg(data);
				}
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url: url
				});
			},
			switchTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.switchTab({
					url: url
				});
			},
			rediTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.redirectTo({
					url: url
				});
			},
			toLogin() {
				uni.redirectTo({
					url: '/pages/public/login'
				});
			}
		}
	};
</script>
<style lang="scss">
	.user-remainder {
		font-size: 26rpx;
		color: #FFFFFF;
		text-align: center;
		line-height: 1.8;
	}

	.member-top-c {
		margin: 0 auto;
	}

	.user-name {
		line-height: 1;
		font-size: 26rpx;
		color: #ffffff;
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10upx;
	}

	.user-section {
		height: 300upx;
		position: relative;
		box-sizing: border-box;
		padding: 55upx 30upx;
		background-color: #1296db;

		.bg {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
		}
	}

	.retailtit {
		width: 100%;
		height: 60upx;
		line-height: 40upx;
		font-size: 32upx;
		font-weight: bold;
		color: #333;
	}

	.retaillist {
		display: flex;
		width: 100%;
		border-bottom: 1upx solid #f6f6f6;
		text-align: center;
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}

	.retaillist:last-child {
		padding-bottom: 0;
		margin-bottom: 0;
		border-bottom: none;
	}

	.retaileach {
		flex: 1;
	}

	.retailtxt {
		font-size: 26upx;
		color: #949494;
		line-height: 50upx;
	}

	.retailname {
		font-size: 36upx;
		color: #e61a0f;
		font-weight: bold;
	}

	.retailtitle {
		font-size: 30upx;
		color: #333;
	}

	.user-info-box {
		height: 190upx;
		display: flex;
		align-items: center;
		position: relative;
		z-index: 1;
		margin: 0 auto;

		.portrait {
			width: 140upx;
			height: 140upx;
			border: 5upx solid #fff;
			border-radius: 50%;
			margin: 0 auto 20upx;
			display: block;

			image {
				width: 130upx;
				height: 130upx;
				border-radius: 50%;
			}
		}

		.username {
			font-size: $font-lg + 6upx;
			color: $font-color-dark;
			margin-left: 20upx;
		}
	}

	.login-btn {
		color: #333;
		width: 180upx;
		height: 50upx;
		line-height: 50upx;
		border-radius: 25upx;
		background: #ffffff;
		font-size: 12px;
	}

	.vip-card-box {
		display: flex;
		flex-direction: column;
		color: #f7d680;
		height: 240upx;
		background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
		border-radius: 16upx 16upx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20upx 24upx;

		.card-bg {
			position: absolute;
			top: 20upx;
			right: 0;
			width: 380upx;
			height: 260upx;
		}

		.b-btn {
			position: absolute;
			right: 20upx;
			top: 16upx;
			width: 132upx;
			height: 40upx;
			text-align: center;
			line-height: 40upx;
			font-size: 22upx;
			color: #36343c;
			border-radius: 20px;
			background: linear-gradient(left, #f9e6af, #ffd465);
			z-index: 1;
		}

		.tit {
			font-size: $font-base + 2upx;
			color: #f7d680;
			margin-bottom: 28upx;

			.yticon {
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}

		.e-b {
			font-size: $font-sm;
			color: #d8cba9;
			margin-top: 10upx;
		}
	}

	.cover-container {
		background: $page-color-base;
		padding: 30upx 30upx;
		position: relative;
		background: #f5f5f5;

		.arc {
			position: absolute;
			left: 0;
			top: -34upx;
			width: 100%;
			height: 36upx;
		}
	}

	.tj-sction {
		@extend %section;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}

		.num {
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.order-section {
		@extend %section;
		padding: 28upx 0;
		margin-top: 20upx;

		.order-item {
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;
		}

		.yticon {
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #e61a0f;
		}

		.icon-shouhoutuikuan {
			font-size: 44upx;
		}
	}

	.history-section {
		background: #fff;
		border-radius: 10upx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}

	.contact-content {
		background: #f5f5f5;
		margin-top: 20rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}

	.meal-content {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		text-align: center;
		padding: 30rpx;

		.meal-item {
			// flex: 1;
			// margin-left: 10rpx;
			font-size: 22rpx;
			height: 120rpx;
			line-height: 120rpx;
			width: 120rpx;
			border-style: solid;
			border-width: 1rpx;
			border-color: #1296db;
			color: #1296db;
		}

		.mealItem {
			// flex: 1;
			// margin-left: 10rpx;
			font-size: 22rpx;
			height: 120rpx;
			line-height: 120rpx;
			width: 120rpx;
			background-color: #1296db;
			color: #fffff
		}

		.meal-item-selected {
			font-size: 22rpx;
			height: 120rpx;
			line-height: 120rpx;
			width: 120rpx;
			background-color: #1296db;
			color: #ffffff;
		}

		.meal-item2 {
			font-size: 24rpx;
			color: #FFFFFF;
			height: 60rpx;
			line-height: 60rpx;
			width: 500rpx;
			background-color: #1296db;
			border-radius: 15rpx;
		}
	}
</style>
